package cn.edu.neusoft.wuguangsheng.flowerimpression.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.SuccessBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.TListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.AddAnswerInfoModel;

public class AddAnswerInfoActivity extends BaseActivity {
    ImageView addanswer_fh;
    EditText addanswer_content;
    TextView addanswer_btn;
    String ask_id;
    @Override
    void initView() {
        setLayout_file(R.layout.activity_add_answer_info);
        addanswer_fh = (ImageView)findViewById(R.id.addanswer_fh);
        addanswer_content = (EditText)findViewById(R.id.addanswer_content);
        addanswer_btn = (TextView)findViewById(R.id.addanswer_btn);
        ask_id = getIntent().getStringExtra("ask_id");
    }

    @Override
    void initEvent() {
        addanswer_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String content = addanswer_content.getText().toString().trim();
                if (content.equals("")){
                    Toast.makeText(AddAnswerInfoActivity.this,"评论内容不能为空",Toast.LENGTH_SHORT).show();
                }
                else {
                    AddAnswerInfoModel addAnswerInfoModel = new AddAnswerInfoModel();
                    addAnswerInfoModel.addAnswerInfo(ask_id, getid(), content, new TListener<SuccessBean>() {
                        @Override
                        public void onResponse(SuccessBean successBean) {
                            if (successBean.getSuccess().equals("1")){
                                Toast.makeText(AddAnswerInfoActivity.this,"评论成功",Toast.LENGTH_SHORT).show();
                                finish();
                            }
                            else {
                                Toast.makeText(AddAnswerInfoActivity.this,"评论失败",Toast.LENGTH_SHORT).show();
                            }
                        }
                        @Override
                        public void onFail(String msg) {
                            Toast.makeText(AddAnswerInfoActivity.this,"网络错误",Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            }
        });
        addanswer_fh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

    @Override
    void initDate() {

    }


}
